package com.ts.api.module.api.service;

import com.gitee.apanlh.web.model.RequestHeader;
import com.ts.api.exp.ApiMsgException;
import com.ts.api.module.api.entity.bo.ApiDecryptBO;
import com.ts.api.module.api.entity.bo.ApiEncryptBO;
import com.ts.api.module.api.entity.bo.ApiHeaderBO;
import com.ts.api.module.api.entity.bo.ApiMsgBO;
import com.ts.api.module.api.entity.po.ApiKeyPO;

/**
 *  API请求验证类
 *
 *  @author Pan
 */
public interface ApiRequestValidateService {

    /**
     * 验证请求头
     *
     * @param  header
     * @return ApiHeaderBO
     */
    ApiHeaderBO validHeader(RequestHeader header) throws ApiMsgException;

    /**
     * 验证客户端
     * 合法性
     *
     * @param   clientId
     * @return  ApiKeyPO
     */
    ApiKeyPO validClient(String clientId);

    /**
     * 验证访问权限
     *
     * @param   apiKeyPO
     * @param   providerType
     */
    void validAccess(ApiKeyPO apiKeyPO, Integer providerType);

    /**
     * 验证签名
     *
     * @param  apiHeaderBO
     * @param  body
     * @param  apiKeyPO
     * @return ApiMsgBO
     * @throws ApiMsgException
     */
    ApiMsgBO validSign(ApiHeaderBO apiHeaderBO, String body, ApiKeyPO apiKeyPO) throws ApiMsgException;

    /**
     * 消息加密方法
     *
     * @param  apiKeyPO
     * @param  ciphertext
     * @return ApiDecryptBO
     * @throws ApiMsgException
     */
    ApiEncryptBO encrypt(ApiKeyPO apiKeyPO, String ciphertext) throws ApiMsgException;

    /**
     * 消息解密方法
     *
     * @param  apiKeyPO
     * @param  ciphertext
     * @return ApiDecryptBO
     * @throws ApiMsgException
     */
    ApiDecryptBO decrypt(ApiKeyPO apiKeyPO, String ciphertext) throws ApiMsgException;


}
